package com.work.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import org.springframework.stereotype.Repository;

import com.work.common.DBUtil;
import com.work.dao.StudentDao;
import com.work.entity.TeacherEntity;



/**
 * com.szrt.spring.annotation
 * com.szrt.spring.annotation.dao.impl
 * 
 * @Repository
 * 
 * 1:  表明StudentDaoImpl接受spring ioc容器的管理
 * @Component 逻辑意义   Component  仓库   表示与数据库相关的类 
 * @Repository 表示我这个类用来与数据库打交道  专门用于dao层  dao database access object 数据库访问对象
 * 
 * @author zsrt
 *
 */

@Repository
public class StudentDaoImpl  implements StudentDao{
	
	public int add(TeacherEntity entity) {
		
		Connection conn = DBUtil.getConn();
		String sql="INSERT INTO spring_teacher_t(TEACHER_NAME,TEACHER_AGE) VALUES(?,?)";
		PreparedStatement ps = null;
		int jg = 0;
		try {
			ps = conn.prepareStatement(sql);
			ps.setString(1,entity.getTeacherName());
			ps.setInt(2, entity.getTeacherAge());
			jg = ps.executeUpdate();
			System.out.println("成功保存");
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		 DBUtil.release(null, ps);
		
		return jg;
	}

	
	
	public StudentDaoImpl(){
		System.err.println("调用StudentDaoImpl无参的构造方法...");
	}
	
	
}
